package com.smbms.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.smbms.pojo.User;
import com.smbms.tools.Constrant;
/**
 * 
 * @author 胡浩然
 *
 */
public class SysInterceptor extends HandlerInterceptorAdapter {
	private Logger logger =Logger.getLogger(SysInterceptor.class);
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) 
			throws Exception {
		logger.info("====>进入拦截器");
		HttpSession session=request.getSession();
		User user =(User) session.getAttribute(Constrant.USER_SESSION);
		if(user!=null){
			return true;
		}
		logger.info("====>用户登录状态丢失");
		response.sendRedirect(request.getContextPath()+"/error.jsp");
		return false;
	}
}
